var util = require('../../libs/util.js');
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {

    //角色切换
    util.getRoleList(this, app.globalData.CO_ID, app.globalData.role_default, app.globalData.roleData);
  },
  reLaunch: function () {
    wx.reLaunch({
      url: '/pages/index/index'
    })
  },
  //角色切换
  changeRole: function (e) {
    var role = e.currentTarget.dataset.role;
    var co_id = e.currentTarget.dataset.co_id;
    app.globalData.role_default = role;
    app.globalData.CO_ID = co_id;
    util.putData("/atapi/user/user/changeDefaultRole", {
      role: role,
      user_id: app.globalData.user_id,
      CO_ID: co_id
    }, function (res, error) {
      console.log(res); console.log(error)
      wx.hideLoading();
      if (error) {
        wx.showToast({
          title: res.data.data,
          image: '/images/wrong.png',
          duration: 3000
        });
        return false;
      }
      if (res.data.success) {
        wx.showModal({
          title: '温馨提示',
          content: '切换默认角色成功！',
          showCancel:false,
          success: function (res) {
            
            wx.redirectTo({
              url: '/pages/index/index'
            })
          }
        })
      } else if (res.data.success == false) {
        wx.showToast({
          title: res.data.data,
          image: '/images/wrong.png',
          duration: 3000,
          mask: true
        });
      }
    });
  },
  //企业切换
  changeCompany: function (e) {
    util.getCompanyList(this, app.globalData.CO_ID, app.globalData.roleData);
    this.setData({
      modalName: 'companyListModal'
    })
  },
  //企业选择
  selectCompany: function (e) {
    var CO_ID = e.currentTarget.dataset.co_id;
    app.globalData.CO_ID = CO_ID;
    this.setData({
      modalName: null
    })
    util.getRoleList(this, app.globalData.CO_ID, '', app.globalData.roleData);
  },
  registerDriver: function () {
    util.registerDriver(app, this)
  },
  registerCompany: function () {
    util.registerCompany(app, this)
  },
  showModal(e) {
    this.setData({
      modalName: e.currentTarget.dataset.target
    })
  },
  hideModal(e) {
    this.setData({
      modalName: null
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  gotoHome: function () {
    wx.navigateTo({
      url: '/pages/fleet/fleet'
    })
  },
  gotoVehicle: function () {
    wx.navigateTo({
      url: '/pages/fleet/vehicle'
    })
  },
  gotoSemitrailer: function () {
    wx.navigateTo({
      url: '/pages/vehicle/semitrailer'
    })
  },
  gotoDriver: function () {
    wx.navigateTo({
      url: '/pages/enterprise/user_driver?type=fleet'
    })
  },
  gotoInfo: function () {
    wx.navigateTo({
      url: '/pages/fleet/apps'
    })
  },
  gotoTransportCapacity:function(){
    wx.navigateTo({
      url: '/pages/vehicle/transport_capacity'
    })
  }
})